//
//  JMAlbumCollectionCell.m
//  PhotoLock
//
//  Created by 赵俊明 on 2017/7/15.
//  Copyright © 2017年 赵俊明. All rights reserved.
//

#import "JMAlbumCollectionCell.h"
#import "JMAlbumModel.h"

@interface JMAlbumCollectionCell()
@property (nonatomic, strong) UILabel *albumType;
@property (nonatomic, strong) UILabel *AlbumCount;
@property (nonatomic, strong) UIButton *leftBtn;

@end

@implementation JMAlbumCollectionCell

- (instancetype)initWithFrame:(CGRect)frame
{
    if ([super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor whiteColor];
//        self.layer.cornerRadius = 5;
//        self.layer.masksToBounds = YES;
        
        _leftBtn = [[UIButton alloc] initWithFrame:CGRectZero];
        _leftBtn.tintColor = JMColor(115, 115, 155);
        [_leftBtn addTarget:self action:@selector(share:event:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.contentView addSubview:_leftBtn];
        
        _albumType = [[UILabel alloc] initWithFrame:CGRectZero];
        _albumType.numberOfLines = 0;
        _albumType.textColor = JMColor(115, 115, 155);
        _albumType.font = [UIFont boldSystemFontOfSize:14];
        [self.contentView addSubview:_albumType];
        
        _AlbumCount = [[UILabel alloc] initWithFrame:CGRectZero];
        _AlbumCount.numberOfLines = 0;
        _AlbumCount.textColor = JMColor(115, 115, 155);
        _AlbumCount.font = [UIFont boldSystemFontOfSize:14];
        [self.contentView addSubview:_AlbumCount];
        
    }
    
    return self;
}

- (void)share:(UIButton *)sender event:(id)event
{
    if ([self.delegate respondsToSelector:@selector(share:)]) {
        
        NSSet *touches =[event allTouches];
        UITouch *touch =[touches anyObject];
        CGPoint currentTouchPosition = [touch locationInView:_collection];
        NSIndexPath *indexpath = [_collection indexPathForItemAtPoint:currentTouchPosition];
        if (indexpath) {[self.delegate share:indexpath];}
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    _leftBtn.frame = CGRectMake(5, 5, self.height-10, self.height-10);
    _albumType.frame = CGRectMake(CGRectGetMaxX(_leftBtn.frame), 5, self.width-CGRectGetMaxX(_leftBtn.frame)-20, self.height/2-5);
    _AlbumCount.frame = CGRectMake(CGRectGetMaxX(_leftBtn.frame), CGRectGetMaxY(_albumType.frame), self.width-CGRectGetMaxX(_leftBtn.frame)-20, self.height/2-5);
}

- (void)setModel:(JMAlbumModel *)model
{
    _model = model;
    [_leftBtn setImage:[UIImage imageNamed:model.leftImage] forState:(UIControlStateNormal)];
    _albumType.text = model.albumType;
    _AlbumCount.text = model.albumCount;
    
}

@end
